﻿
namespace IocContainerExample.TestHarness
{
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;

   /*====================================================================================
   EXAMPLE UNITY ADAPTOR THAT CAN BE USED IN CONJUNCTION WITH THE MODULE LOADER
    * ====================================================================================*/


   /*
   public class UnityAdaptor : IIocContainer
   {
      private bool disposed = false;

      private IUnityContainer container;

      public UnityAdaptor()
      {
         container = new UnityContainer();

      }
      public void Dispose()
      {
         Dispose(true);
         GC.SuppressFinalize(this);
      }

      // Protected implementation of Dispose pattern.
      protected virtual void Dispose(bool disposing)
      {
         if (disposed)
            return;

         if (disposing)
         {
            container.Dispose();
         }

         disposed = true;
      }

      public void Register(System.Type TInterface, System.Type TType, Lifetime life = Lifetime.PerInstance, params object[] constructorArgs)
      {
         if (life == Lifetime.PerInstance)
         {
            container.RegisterType(TInterface, TType, new PerResolveLifetimeManager(), new InjectionConstructor(constructorArgs));
         }
         else
         {
            container.RegisterType(TInterface, TType, new ContainerControlledLifetimeManager(), new InjectionConstructor(constructorArgs));
         }
      }

      public void Register(System.Type TType, Lifetime life = Lifetime.PerInstance, params object[] constructorArgs)
      {

         InjectionConstructor args = null;
         if (constructorArgs.Length > 0)
         {
            args = new InjectionConstructor(constructorArgs);
         }

         if (life == Lifetime.PerInstance)
         {
            if (args != null)
            {
               container.RegisterType(TType, new PerResolveLifetimeManager(), args);
            }
            else
            {
               container.RegisterType(TType, new PerResolveLifetimeManager());
            }
         }
         else
         {
            if (args != null)
            {
               container.RegisterType(TType, new ContainerControlledLifetimeManager(), args);
            }
            else
            {
               container.RegisterType(TType, new ContainerControlledLifetimeManager(), args);
            }
         }
      }

      public void Register<TInterface, TType>(Lifetime life = Lifetime.PerInstance, params object[] constructorArgs)
      {
         Register(typeof(TInterface), typeof(TType), life, constructorArgs);
      }

      public void Register<TType>(Lifetime life = Lifetime.PerInstance, params object[] constructorArgs)
      {
         Register(typeof(TType), life, constructorArgs);
      }

      public void RegisterInstance<TType>(TType instance)
      {
         container.RegisterInstance(instance, new ContainerControlledLifetimeManager());
      }

      public void RegisterTypesOf<TAttribute>()
      {
         throw new NotImplementedException("");
      }

      public bool RegisterUnResolvedTypes
      {
         get
         {
            return false;
         }
         set
         {
            bool x = value;
         }
      }

      public object Resolve(System.Type type)
      {
         return container.Resolve(type);
      }

      public TType Resolve<TType>()
      {
         return container.Resolve<TType>();
      }
   }
   */
}
